//WMPMenu.h
#include "..\WMP\List.h"

#pragma once

#define MENU_MAX_ID 56000
#define MENU_MIN_ID 40000

class WMPMenu;

class WMPMenuItem {
	WMPMenu* owner;
	WORD id;
	LPTSTR text;
	bool checked;
	bool enabled;
public:
	inline WORD getID() { return this->id; }
	inline LPTSTR getText() { return this->text; }

	WMPMenuItem(WMPMenu* owner, LPTSTR text);
	~WMPMenuItem();
	bool Insert(HMENU hMenu, BOOL byPos, UINT pos);
	bool InitID();
	bool Invoke(HWND hWnd);
};

enum SUBMENU_PLACE: int {
	SUBMENU_PLACE_CUSTOM,
	SUBMENU_PLACE_BEGIN_POS,
	SUBMENU_PLACE_END_POS,
	SUBMENU_PLACE_BEFORE_ID,
	SUBMENU_PLACE_AFTER_ID
};

class WMPSubMenu {
	WMPMenu* owner;
	HMENU hMenu;
	LPTSTR text;
	SUBMENU_PLACE place;
	UINT id;
public:
	inline HMENU getMenu() { return this->hMenu; }
	void setMenu(HMENU hMenu);
	inline LPTSTR getText() { return this->text; }

	WMPSubMenu(WMPMenu* owner, LPTSTR text, SUBMENU_PLACE place, UINT id);
	~WMPSubMenu();
	int Place(HMENU hMenu);
	void Invoke(HMENU hMenu);
};

class WMPMenu {
	WORD id;
	List<WORD, WMPMenuItem*>* items;
	List<HMENU, WMPSubMenu*>* menus;
	CArray<WMPSubMenu*>* submenus;
public:
	WMPMenu();
	~WMPMenu();
	bool NextID(int pool, WORD &minID, WORD &maxID);
	void AddItem(WMPMenuItem* item);
	void RemoveItem(WMPMenuItem* item);
	void AddSubMenu(WMPSubMenu* menu);
	void RemoveSubMenu(WMPSubMenu* menu);
	void DeleteSubMenu(HMENU hMenu, UINT item);
	void AddMenu(WMPSubMenu* menu);
	void RemoveMenu(WMPSubMenu* menu);
	void Clear();
	bool InvokeMenuItem(HWND hWnd, WORD id);
	void InvokeSubMenu(HWND hWnd, HMENU hMenu);
	HMENU CreateSubMenu(HMENU hMenu, UINT item, LPTSTR text);
};

WMPMenuItem* WINAPI CreateWMPMenuItem(WMPMenu *menu, LPTSTR text);
void WINAPI DestroyWMPMenuItem(WMPMenuItem *item);
WMPSubMenu* WINAPI CreateWMPSubMenu(WMPMenu* menu, LPTSTR text, SUBMENU_PLACE place, UINT id);
void WINAPI DestroyWMPSubMenu(WMPSubMenu *menu);
BOOL WINAPI InsertWMPMenuItem(WMPMenuItem* item, HMENU hMenu, int pos);
int FindMenuItem(HMENU hMenu, UINT id);
